package org.blog.service.impl;

import org.blog.dao.CategoryMapper;
import org.blog.dao.CommentsMapper;
import org.blog.entity.Comments;
import org.blog.entity.param.CommentsParam;
import org.blog.service.CommentsService;
import org.blog.utils.ObjectToMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

@Service
public class CommentsServiceImpl implements CommentsService {
    @Autowired
    private CommentsMapper commentsMapper;
    @Override
    public List<Comments> getComments(CommentsParam param) {
        Map<String, Object> stringObjectMap = null;
        try {
            stringObjectMap = ObjectToMap.convertBeanToMap(param);
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        List<Comments>  list = commentsMapper.getComments(stringObjectMap);
        return list;
    }

    @Override
    public boolean delete(Integer commentsId) {
        int i = commentsMapper.deleteByPrimaryKey(commentsId);
        if (i > 0) {
            return true;
        }
        return false;
    }

}
